\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md17}{}\doxysection{Developer\textquotesingle{}s Guide}\label{md_doc_sphinx_source_General_Develop_autotoc_md17}
\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md18}{}\doxysubsection{Abbreviations}\label{md_doc_sphinx_source_General_Develop_autotoc_md18}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ prefix/suffix }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ meaning  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ prefix/suffix }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ meaning  }\\\cline{1-2}
\endhead
$\ast$\+\_\+L, {\itshape W$\ast$ }&{\itshape  Local frame, World frame  }\\\cline{1-2}
{\itshape  $\ast$fe}$\ast$ &foot end  \\\cline{1-2}
$\ast$\+\_\+L, \+\_\+l, \+\_\+R, \+\_\+r$\ast$ &Left, Right  \\\cline{1-2}
{\itshape swing,} {\itshape sw} &swing leg  \\\cline{1-2}
{\itshape stance,} {\itshape st} &stance leg  \\\cline{1-2}
{\itshape eul, rpy} &angular position expressed by euler angle  \\\cline{1-2}
{\itshape omega} &angular velocity  \\\cline{1-2}
{\itshape pos} &linear position  \\\cline{1-2}
{\itshape vel} &linear velocity  \\\cline{1-2}
{\itshape tor}, tau$\ast$ &torque at joint  \\\cline{1-2}
{\itshape base} &baselink  \\\cline{1-2}
$\ast$\+\_\+des$\ast$ &desired value  \\\cline{1-2}
$\ast$\+\_\+cur$\ast$ &current value  \\\cline{1-2}
$\ast$\+\_\+rot$\ast$ &rotation matrix  \\\cline{1-2}
\end{longtabu}
\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md19}{}\doxysubsection{key control parameters}\label{md_doc_sphinx_source_General_Develop_autotoc_md19}

\begin{DoxyItemize}
\item \mbox{\hyperlink{classMPC}{M\+PC}} parameters 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{//MPC.h}
\DoxyCodeLine{void    set\_weight(double u\_weight, Eigen::MatrixXd L\_diag, Eigen::MatrixXd K\_diag);}
\DoxyCodeLine{//*u\_weight* : the minimal weight of control input}
\DoxyCodeLine{//*L\_diag* : the weight of error compared to desired values, following the order (eul, pos, omega, vel)}
\DoxyCodeLine{//*K\_diag* : the weight of control input, following the order (fl, tl, fr, tr)}
\end{DoxyCode}

\item W\+BC priority 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{//WBC\_QP.cpp}
\DoxyCodeLine{std::vector<std::string taskOrder;}
\DoxyCodeLine{taskOrder.emplace\_back("RedundantJoints");}
\DoxyCodeLine{taskOrder.emplace\_back("static\_Contact");}
\DoxyCodeLine{taskOrder.emplace\_back("Roll\_Pitch\_Yaw\_Pz");}
\DoxyCodeLine{taskOrder.emplace\_back("PxPy");}
\DoxyCodeLine{taskOrder.emplace\_back("SwingLeg");}
\DoxyCodeLine{taskOrder.emplace\_back("HandTrack");}
\DoxyCodeLine{// add task or adjust the priority here}
\end{DoxyCode}

\item W\+BC weight 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{//PriorityTasks.h}
\DoxyCodeLine{Eigen::MatrixXd Kp;                //weight of position error}
\DoxyCodeLine{Eigen::MatrixXd Kd;                //weight of velocity eror}
\DoxyCodeLine{//WBC\_QP.h}
\DoxyCodeLine{Eigen::MatrixXd Q1;                //weight of the contact force error compared to desired, following the order (fl, tl, fr, tr)}
\DoxyCodeLine{Eigen::MatrixXd Q2;                //weight of the acceleration tracking error}
\end{DoxyCode}

\item Swing leg trajectory 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{//FootPlacement.h}
\DoxyCodeLine{double kp\_vx;                                 //x-\/direction footplacement parameter}
\DoxyCodeLine{double kp\_vy;                                 //y-\/direction footplacement parameter}
\DoxyCodeLine{double kp\_wz;                                 //z-\/direction posture parameter}
\DoxyCodeLine{double stepHeight;                            //the maximal step height}
\DoxyCodeLine{}
\DoxyCodeLine{//FootPlacement.cpp}
\DoxyCodeLine{double    FootPlacement::Trajectory(double phase, double des1, double des2);        //z-\/direction posture trajectory}
\DoxyCodeLine{//phase：the phase when reaching the highest}
\DoxyCodeLine{//des1：the highest position along the trajectory}
\DoxyCodeLine{//des2：the final position of the trajectory}
\end{DoxyCode}

\item Gait control 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{//GaitScheduler.h}
\DoxyCodeLine{double tSwing;                                         //the time of one step}
\DoxyCodeLine{double FzThrehold;                                     //the maximal force when touching the ground}
\DoxyCodeLine{}
\DoxyCodeLine{//GaitScheduler.cpp}
\DoxyCodeLine{DataBus::LegState legState=DataBus::RSt;                //the first step state}
\end{DoxyCode}

\item Joint parameter 
\begin{DoxyCode}{0}
\DoxyCodeLine{//JointCtrConfig.json}
\DoxyCodeLine{   "Joint-\/ankel-\/l-\/pitch" : \{}
\DoxyCodeLine{      "PVT\_LPF\_Fc" : 20,}
\DoxyCodeLine{      "kd" : 5.0,}
\DoxyCodeLine{      "kp" : 50.0,}
\DoxyCodeLine{      "maxPos" : 0.61087,}
\DoxyCodeLine{      "maxSpeed" : 48.8,}
\DoxyCodeLine{      "maxTorque" : 58.5,}
\DoxyCodeLine{      "minPos" : -\/0.43644}
\DoxyCodeLine{   \}}
\end{DoxyCode}

\end{DoxyItemize}\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md20}{}\doxysubsection{Instructions to replace robot model}\label{md_doc_sphinx_source_General_Develop_autotoc_md20}
\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md21}{}\doxysubsubsection{model file}\label{md_doc_sphinx_source_General_Develop_autotoc_md21}
{\bfseries{1. xml file preparation}}

prepare the urdf (.urdf) file and mesh file (.stl) of the robot for adding the mujoco compiling tags 
\begin{DoxyCode}{0}
\DoxyCodeLine{<\textcolor{keywordtype}{mujoco}>}
\DoxyCodeLine{<\textcolor{keywordtype}{compiler}}
\DoxyCodeLine{        \textcolor{keyword}{meshdir}=\textcolor{stringliteral}{"meshes/"}}
\DoxyCodeLine{        \textcolor{keyword}{balanceinertia}=\textcolor{stringliteral}{"true"}}
\DoxyCodeLine{        \textcolor{keyword}{discardvisual}=\textcolor{stringliteral}{"false"} />}
\DoxyCodeLine{</\textcolor{keywordtype}{mujoco}>}
\end{DoxyCode}


change the working directory to {\ttfamily mujoco-\/3.\+x.\+x/bin}, run the command\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{./simulate}
\end{DoxyCode}


drag the urdf file into the simulation interface, after the model displaying correctly save the xml file. You should note the path of the mesh files.

You can also reference the Mujoco \href{https://mujoco.readthedocs.io/en/stable/XMLreference.html}{\texttt{ documentation}} to set tags like {\ttfamily compiler}, {\ttfamily option} or {\ttfamily asset} to customize {\ttfamily body}, {\ttfamily actuator} and {\ttfamily sensor} etc.

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ parent label }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ child label  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ parent label }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ child label  }\\\cline{1-2}
\endhead
{\itshape worldbody} &define light, camera, floor and robot(inertial, joint, freejoint, geom, site, camera, light etc)  \\\cline{1-2}
{\itshape actuator} &define actuators (motor, position, velocity etc)  \\\cline{1-2}
{\itshape sensor} &define the sensors and adjust the sensors parameters like noises  \\\cline{1-2}
\end{longtabu}


{\bfseries{2. replace the model}}

Take the \char`\"{}\+Azure\+Dragon robot\char`\"{} as an example\+: under {\itshape base\+\_\+link}, there are four tandem connections in parallel\+: the head {\itshape Link\+\_\+head\+\_\+}, the waist {\itshape Link\+\_\+waist\+\_\+}, the left arm {\itshape Link}\+\_\+arm\+\_\+l\+\_\+, and the right arm {\itshape Link\+\_\+arm\+\_\+r\+\_\+} branches. The left arm and right arm branches each have 7 degrees of freedom and the head branch has 2 degrees of freedom. The waist branch has 3 degrees of freedom including pitch$\ast$\+Link\+\_\+waist\+\_\+pitch$\ast$, roll$\ast$\+Link\+\_\+waist\+\_\+roll$\ast$, yaw$\ast$\+Link\+\_\+waist\+\_\+yaw$\ast$, etc., and the left leg and right leg branches are connected in parallel, and each leg is connected with three hip joints$\ast$\+Link\+\_\+$\ast$hip$\ast$ and one knee joint$\ast$\+Link\+\_\+knee\+\_\+$\ast$ in turn, two ankle joints {\itshape Link\+\_\+ankel\+\_\+} and in total 6 degrees of freedom. This completes the configuration of all the 31 degrees of freedom.

You can reference this configuration and try to customize your configuration.


\begin{DoxyCode}{0}
\DoxyCodeLine{<\textcolor{keywordtype}{worldbody}>}
\DoxyCodeLine{    <\textcolor{keywordtype}{body} \textcolor{keyword}{name}=\textcolor{stringliteral}{"base\_link"} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"x x x"}>}
\DoxyCodeLine{        <\textcolor{keywordtype}{freejoint} \textcolor{keyword}{name}=\textcolor{stringliteral}{"float\_base"} />}
\DoxyCodeLine{        <\textcolor{keywordtype}{body} \textcolor{keyword}{name}=\textcolor{stringliteral}{"body1"} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"x x x"}>}
\DoxyCodeLine{            <\textcolor{keywordtype}{inertial} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"x x x"} \textcolor{keyword}{quat}=\textcolor{stringliteral}{"x x x"} \textcolor{keyword}{mass}=\textcolor{stringliteral}{"x"} \textcolor{keyword}{diaginertia}=\textcolor{stringliteral}{"x x x"}/>}
\DoxyCodeLine{            <\textcolor{keywordtype}{joint} \textcolor{keyword}{name}=\textcolor{stringliteral}{"joint1"} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"0 0 0"} \textcolor{keyword}{axis}=\textcolor{stringliteral}{"1 0 0"} \textcolor{keyword}{limited}=\textcolor{stringliteral}{"true"} \textcolor{keyword}{range}=\textcolor{stringliteral}{"x x"}/>}
\DoxyCodeLine{            <\textcolor{keywordtype}{geom} \textcolor{keyword}{type}=\textcolor{stringliteral}{"mesh"} \textcolor{keyword}{contype}=\textcolor{stringliteral}{"0"} \textcolor{keyword}{conaffinity}=\textcolor{stringliteral}{"0"} \textcolor{keyword}{group}=\textcolor{stringliteral}{"1"} \textcolor{keyword}{density}=\textcolor{stringliteral}{"0"} \textcolor{keyword}{rgba}=\textcolor{stringliteral}{"x x x 1"} \textcolor{keyword}{mesh}=\textcolor{stringliteral}{"body1"}/>}
\DoxyCodeLine{            <\textcolor{keywordtype}{geom} \textcolor{keyword}{type}=\textcolor{stringliteral}{"mesh"} \textcolor{keyword}{rgba}=\textcolor{stringliteral}{"x x x 1"} \textcolor{keyword}{mesh}=\textcolor{stringliteral}{"body1"}/>}
\DoxyCodeLine{            <\textcolor{keywordtype}{body} \textcolor{keyword}{name}=\textcolor{stringliteral}{"body2"} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"x x x"}>}
\DoxyCodeLine{                ...}
\DoxyCodeLine{                <\textcolor{keywordtype}{joint} \textcolor{keyword}{name}=\textcolor{stringliteral}{"joint2"} .../>}
\DoxyCodeLine{                ...}
\DoxyCodeLine{            </\textcolor{keywordtype}{body}>}
\DoxyCodeLine{        </\textcolor{keywordtype}{body}>}
\DoxyCodeLine{        <\textcolor{keywordtype}{body} \textcolor{keyword}{name}=\textcolor{stringliteral}{"body3"} \textcolor{keyword}{pos}=\textcolor{stringliteral}{"x x x"}>}
\DoxyCodeLine{            ...}
\DoxyCodeLine{            <\textcolor{keywordtype}{joint} \textcolor{keyword}{name}=\textcolor{stringliteral}{"joint3"} .../>}
\DoxyCodeLine{            ...}
\DoxyCodeLine{        </\textcolor{keywordtype}{body}>}
\DoxyCodeLine{    </\textcolor{keywordtype}{body}>}
\DoxyCodeLine{</\textcolor{keywordtype}{worldbody}>}
\end{DoxyCode}


In this case, two branches are connected in parallel under {\itshape base\+\_\+link}, one branch consists of {\itshape body1} and {\itshape body2} in series, and the other branch consists of {\itshape body3}. If the robot has a floating base, add the free joint {\itshape freejoint} under {\itshape body} named {\itshape base\+\_\+link} above. If the robot is a fixed base, remove the {\itshape freejoint} . Optionally, {\itshape freejoint} can be masked out during the model configuration phase, if desired.

This project sets actuator for each of the 31 joints.


\begin{DoxyCode}{0}
\DoxyCodeLine{<\textcolor{keywordtype}{actuator}>}
\DoxyCodeLine{    <\textcolor{keywordtype}{motor} \textcolor{keyword}{name}=\textcolor{stringliteral}{"motor1"}  \textcolor{keyword}{joint}=\textcolor{stringliteral}{"joint1"} \textcolor{keyword}{gear}=\textcolor{stringliteral}{"x"} \textcolor{keyword}{ctrllimited}=\textcolor{stringliteral}{"true"} \textcolor{keyword}{ctrlrange}=\textcolor{stringliteral}{"x x"}/>}
\DoxyCodeLine{    ...}
\DoxyCodeLine{</\textcolor{keywordtype}{actuator}>}
\end{DoxyCode}


The user can define the corresponding actuators at the active joints depending on the degrees of freedom of the robot.

The project is configured with sensors such as quaternion {\itshape framequat}, velocimeter {\itshape velocimeter}, angular velocimeter {\itshape gyro}, accelerometer {\itshape accelerometer}, which are mounted at the {\itshape site} already defined in the {\itshape body} tag, and can be added according to the needs of {\itshape touch}, {\itshape force}, {\itshape torque}, {\itshape jointpos}, {\itshape jointvel}, {\itshape actuatorfrc}, {\itshape actuatorfrc}. force$\ast$, {\itshape torque}, {\itshape jointpos}, {\itshape jointvel}, {\itshape actuatorfrc} and other sensors can be added as required.


\begin{DoxyCode}{0}
\DoxyCodeLine{<\textcolor{keywordtype}{sensor}>}
\DoxyCodeLine{    <\textcolor{keywordtype}{framequat} \textcolor{keyword}{name}=\textcolor{stringliteral}{"xx"} \textcolor{keyword}{objtype}=\textcolor{stringliteral}{"site"} \textcolor{keyword}{objname}=\textcolor{stringliteral}{"imu"} />}
\DoxyCodeLine{    <\textcolor{keywordtype}{velocimeter} \textcolor{keyword}{name}=\textcolor{stringliteral}{"xx"} \textcolor{keyword}{site}=\textcolor{stringliteral}{"imu"} />}
\DoxyCodeLine{    <\textcolor{keywordtype}{gyro} \textcolor{keyword}{name}=\textcolor{stringliteral}{"xx"} \textcolor{keyword}{site}=\textcolor{stringliteral}{"imu"} />}
\DoxyCodeLine{    <\textcolor{keywordtype}{accelerometer} \textcolor{keyword}{name}=\textcolor{stringliteral}{"xx"} \textcolor{keyword}{site}=\textcolor{stringliteral}{"imu"} />}
\DoxyCodeLine{</\textcolor{keywordtype}{sensor}>}
\end{DoxyCode}


In addition to the degree of freedom configuration, actuator configuration, sensor configuration, other more specific parameter modifications can refer to the Mojoco official \href{https://mujoco.readthedocs.io/en/stable/XMLreference.html}{\texttt{ documentation}}.\hypertarget{md_doc_sphinx_source_General_Develop_autotoc_md22}{}\doxysubsubsection{Control code and Mujoco interface}\label{md_doc_sphinx_source_General_Develop_autotoc_md22}
Use fuction {\ttfamily mj\+\_\+load\+X\+ML}, {\ttfamily mj\+\_\+make\+Data}to get {\ttfamily mj\+Model}, {\ttfamily mj\+Data} struct. You can reference the \href{https://mujoco.readthedocs.io/en/stable/XMLreference.html}{\texttt{ documentation}} for more details of {\ttfamily mj\+Model}, {\ttfamily mj\+Data}, {\ttfamily mj\+Option}. 
\begin{DoxyCode}{0}
\DoxyCodeLine{ \{C++\}}
\DoxyCodeLine{mjModel* mj\_model = mj\_loadXML("../Models/xxx.xml", 0, error, 1000);}
\DoxyCodeLine{mjData* mj\_data = mj\_makeData(mj\_model);}
\end{DoxyCode}


{\ttfamily mj\+\_\+model-\/$>$nv} is the dimension of generalized velocity coordinate, i.\+e. the linear velocity, angular velocity of the floating base, and the velocity of the 31 joints of the rotational type. The variables related to the degrees of freedom in the program framework of the project are corresponding to {\ttfamily mj\+\_\+model-\/$>$nv-\/6}, and the dynamics library will automatically get the dimensions of the degrees of freedom of the robot according to the U\+R\+DF, where all the dimension information are defined. Thus users don\textquotesingle{}t have to modify it in the program manually.

As the access to the addresses of {\itshape body}, {\itshape joint}, {\itshape motor} and other components of this project relies on querying the name string and locking the address, when a component is modified, it will not affect the data reading and writing of other {\itshape body}, {\itshape joint}, and provide convenience for modifying the model compared to the direct indexing number. When modifying the control parameters of a certain degree of freedom in the model, you only need to modify the {\ttfamily Joint\+Name} of {\itshape M\+J\+\_\+\+Interface.\+h}, the {\ttfamily motor\+Name} of {\itshape Pin\+\_\+\+Kin\+Dyn.\+h}, the {\ttfamily motor\+Name} of {\itshape P\+V\+T\+\_\+\+Ctr.\+h}, and the variables corresponding to the name of a certain degree of freedom in the {\itshape Joint\+Ctr\+Config.\+json} file. For example, to modify the stiffness of {\ttfamily J\+\_\+waist\+\_\+pitch}, you need to modify {\ttfamily J\+\_\+waist\+\_\+pitch} and the corresponding PD parameter in {\itshape Joint\+Ctr\+Config.\+json}, and the name of {\ttfamily J\+\_\+waist\+\_\+pitch} corresponds to the {\itshape joint name}, {\itshape motor name} in the xml file.

The sensor data address is also accessed by querying the name string to find the address, adding or deleting sensors can be done by modifying the corresponding sensor name in {\itshape M\+J\+\_\+\+Interface.\+h}. 